﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.Caching;
using System.Web.Configuration;

namespace Feelingme.ShareMSDN
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            this.Application["ship.htm"] = SharedUtil.GetHtmlFromResource("ship.htm");
            //CacheDatabase(null, null, CacheItemRemovedReason.Removed);                           
        }

        //private void CacheDatabase(string key, object value, CacheItemRemovedReason reason)
        //{
        //    this.Context.Cache.Add(
        //        "msdn-db",
        //        CacheUtil.CreateDatabaseCopy<MSDNEntities>(
        //            WebConfigurationManager.ConnectionStrings["MSDNEntities"].ConnectionString),
        //        null,
        //        Cache.NoAbsoluteExpiration,
        //        new TimeSpan(1, 0, 0),
        //        CacheItemPriority.Normal,
        //        CacheDatabase);
        //}

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception x = Server.GetLastError().GetBaseException();
            Response.StatusCode = 500;
            Response.Write("<b>[Share MSDN Online] 500 - Critical error occured in the current context, please contact author stainboyx@hotmail.com</b><br/>");
            Response.Write(x.GetType().FullName + ": " + x.Message + "</br>");
#if DEBUG
            Response.Write(x.ToString());
#endif
            Response.End();

            EventLog.WriteEntry("ShareMSDNOnline", x.Message, EventLogEntryType.Error);
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}